<?php

namespace App\Http\Controllers\Cron;

use App\Http\Controllers\Controller;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Http\Request;
use GuzzleHttp\Client;

class WebController extends Controller
{

    //百度普通收录
    public function baiduEmploy(Request $request)
    {
        $urls = array(
            'http://www.xiaocai.ink',
        );
        $api = 'http://data.zz.baidu.com/urls?site=https://www.xiaocai.ink&token=a4FGyHydalsu6CRy';
        try {
            $ch = curl_init();
            $options =  array(
                CURLOPT_URL => $api,
                CURLOPT_POST => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_POSTFIELDS => implode("\n", $urls),
                CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
            );
            curl_setopt_array($ch, $options);
            $result = curl_exec($ch);
            $result = json_decode($result,true);
            if(isset($result['error'])){
                echo $result['message']." 当天已没有剩余的可推送url条数";
                exit();
            }
            echo "推送成功"."，剩余推送次数：".$result['remain'];

        }catch (\Exception $e){
            echo $e->getMessage();
        }

    }


}
